/************************************************************************** * * Language: C++ * Purpose: Program to demonstrate the 'new' statement. * Author: M J Leslie * Date: 27-Sep-98 * * Initialise a constant within a class. * **************************************************************************/ #include <iostream.h> // For cout. class Math { public: // Constructor contains the definition of PI. Math() : PI(3.142) {} ~Math() {} float Diameter (float Radius) { return (Radius * PI); } private: // Declare PI. We can not assign a value here. const float PI; }; main() { Math Formula; float Radius = 5; cout << " Radius is " << Radius << endl; cout << " Diameter is " << Formula.Diameter(Radius) << endl; }
file: /Techref/language/ccpp/cppref/examples/const1.cc, 0KB, , updated: 1998/9/27 12:50, local time: 2024/5/18 09:34,
13.59.254.80:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://techref.massmind.org/techref/language/ccpp/cppref/examples/const1.cc"> language ccpp cppref examples const1</A> |
Did you find what you needed? |
Welcome to massmind.org! |
Ashley Roll has put together a really nice little unit here. Leave off the MAX232 and keep these handy for the few times you need true RS232! |
.